package com.wz.jiangsu.wangteng.kafka.partitioner;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @program: event_query
 * @author: wangzhou
 * @create: 2023-11-16 11:27
 * @description:
 **/
@Component
public class CustomizePartitioner implements Partitioner {
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        // 获取消息
        String msg = value.toString();
        System.out.println("msg:" + msg);
        int position = 1;
        if (msg.contains("wangteng")) {
            position = 0;
        }
        return position;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
